#!/usr/bin/bash

# Changing into workingdir and creating it, if it doesn't exist
mkdir -p ~/.slack-updater/
cd ~/.slack-updater/

# Remove previous changelog to prevent clustering
rm ChangeLog.txt

# Downloading the changelog (uses the one configured in your "/etc/slackpkg/mirrors")
CL_MIRROR=$(cat /etc/slackpkg/mirrors | grep -v "#")ChangeLog.txt
wget $CL_MIRROR

# Comparing new changelog to old one
UPGRADE_NOTIFY=$(diff ChangeLog.old.txt ChangeLog.txt | grep .txz)

# Sending results to your notification-daemon
# you can add "--icon=/PATH/TO/SOME/ICON.png" if you want the notification to have one
# expire-time is set to 0 in order to ignore timeout (stays until you click on it)
notify-send --expire-time=0 "Checked out the Repositories:" "$UPGRADE_NOTIFY"

# There are two behaviors available from here:

# 1 - this one will NOT replace the old changelog automatically and requires you to do so manually, as soon as you updated your packages.
echo "Nothing to do here."

# 2 - this one will immeditaley replace the old changelog with the new one, whether you upgraded your packages or not. (DISABLED BY DEFAULT)
#rm ~/.slack-updater/ChangeLog.old.txt
#mv ~/.slack-updater/ChangeLog.txt ~/.slack-updater/ChangeLog.old.txt

